<!DOCTYPE HTML>
<html>

<head>
	<link rel="bookmark"  type="image/x-icon"  href="/img/logo_miccall.png"/>
	<link rel="shortcut icon" href="/img/logo_miccall.png">
	
			    <title>
    Ame雨
    </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <link rel="stylesheet" href="/amelin-ting/css/mic_main.css" />
    <link rel="stylesheet" href="/amelin-ting/css/dropdownMenu.css" />
    <meta name="keywords" content="Ame雨" />
    
    	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
	 
    <noscript>
        <link rel="stylesheet" href="/amelin-ting/css/noscript.css" />
    </noscript>
    <style type="text/css">
        body:before {
          content: ' ';
          position: fixed;
          top: 0;
          background: url('/amelin-ting/img/bg.jpg') center 0 no-repeat;
          right: 0;
          bottom: 0;
          left: 0;
          background-size: cover; 
        }
    </style>

			    
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script async type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


    <script src="/amelin-ting/js/jquery.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrollex.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrolly.min.js"></script>
    <script src="/amelin-ting/js/skel.min.js"></script>
    <script src="/amelin-ting/js/util.js"></script>
    <script src="/amelin-ting/js/main.js"></script>
	
<meta name="generator" content="Hexo 5.4.0"></head>
    
		
<!-- Layouts -->



<!--  代码渲染  -->
<link rel="stylesheet" href="/css/prism_coy.css" />
<link rel="stylesheet" href="/css/typo.css" />
<!-- 文章页 -->
<body class="is-loading">
    <!-- Wrapper 外包 s-->
    <div id="wrapper" class="fade-in">
        <!-- Intro 头部显示 s -->
        <!-- Intro 头部显示 e -->
        <!-- Header 头部logo start -->
        <header id="header">
    <a href="/amelin-ting/" class="logo">Art Space</a>
</header>
        <!-- Nav 导航条 start -->
        <nav id="nav" class="special" >
            <ul class="menu links" >
			<!-- Homepage  主页  --> 
			<li >
	            <a href="/amelin-ting/" rel="nofollow">主页</a>
	        </li>
			<!-- categories_name  分类   --> 
	        
	        <li class="active">
	            <a href="#s1">分类</a>
	                    <ul class="submenu">
	                        <li>
	                        <a class="category-link" href="/amelin-ting/categories/Go/">Go</a></li><li><a class="category-link" href="/amelin-ting/categories/django/">django</a></li><li><a class="category-link" href="/amelin-ting/categories/drf/">drf</a></li><li><a class="category-link" href="/amelin-ting/categories/gin/">gin</a></li><li><a class="category-link" href="/amelin-ting/categories/go/">go</a></li><li><a class="category-link" href="/amelin-ting/categories/linux/">linux</a></li><li><a class="category-link" href="/amelin-ting/categories/mysql/">mysql</a></li><li><a class="category-link" href="/amelin-ting/categories/python/">python</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">内网穿透</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%89%8D%E7%AB%AF/">前端</a>
	                    </ul>
	        </li>
	        
	        <!-- archives  归档   --> 
	        
	        
		        <!-- Pages 自定义   -->
		        
		        <li>
		            <a href="/about/" title="简历">
		                简历
		            </a>
		        </li>
		        
		        <li>
		            <a href="/group/" title="团队">
		                团队
		            </a>
		        </li>
		        
		        <li>
		            <a href="/gallery/" title="图库">
		                图库
		            </a>
		        </li>
		        
		        <li>
		            <a href="/tag/" title="标签">
		                标签
		            </a>
		        </li>
		        


            </ul>
            <!-- icons 图标   -->
			<ul class="icons">
                    
                    <li>
                        <a title="github" href="https://github.com/miccall" target="_blank" rel="noopener">
                            <i class="icon fa fa-github"></i>
                        </a>
                    </li>
                    
                    <li>
                        <a title="500px" href="http://500px.com" target="_blank" rel="noopener">
                            <i class="icon fa fa-500px"></i>
                        </a>
                    </li>
                    
			</ul>
</nav>

        <div id="main" >
            <div class ="post_page_title_img" style="height: 25rem;background-image: url(https://img1.baidu.com/it/u=2253949680,1685037572&amp;fm=26&amp;fmt=auto);background-position: center; background-repeat:no-repeat; background-size:cover;-moz-background-size:cover;overflow:hidden;" >
                <a href="#" style="padding: 4rem 4rem 2rem 4rem ;"><h2 >Python入门知识点</h2></a>
            </div>
            <!-- Post -->
            <div class="typo" style="padding: 3rem;">
                <h2 id="一、变量"><a href="#一、变量" class="headerlink" title="一、变量"></a>一、变量</h2><h3 id="1-1-什么是变量"><a href="#1-1-什么是变量" class="headerlink" title="1.1 什么是变量"></a>1.1 什么是变量</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">变量 正如他的名字 分成两个字来看  变和量   量是个意思很广泛的词，就是指事物的状态，然后再看变，变化的意思，合起来看就是一个变化的事物的状态</span><br></pre></td></tr></table></figure>

<h3 id="1-2-为什么要有变量"><a href="#1-2-为什么要有变量" class="headerlink" title="1.2 为什么要有变量"></a>1.2 为什么要有变量</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">因为在三次元人类世界中，存在很多变化的事物，人类要想跟计算机沟通，让计算机替人类办事，首先就得在计算机中弄一个人类世界，自然也就要有一个计算机能理解的变化的事物</span><br></pre></td></tr></table></figure>

<h3 id="1-3-怎么使用变量（先定义-后调用）"><a href="#1-3-怎么使用变量（先定义-后调用）" class="headerlink" title="1.3 怎么使用变量（先定义 后调用）"></a>1.3 怎么使用变量（先定义 后调用）</h3><h4 id="1-3-1-变量的定义与使用"><a href="#1-3-1-变量的定义与使用" class="headerlink" title="1.3.1 变量的定义与使用"></a>1.3.1 变量的定义与使用</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 定义其实就是   “变量名”    =     “值”  </span></span><br><span class="line">name = <span class="string">&quot;Ame&quot;</span></span><br><span class="line">age = <span class="number">18</span></span><br><span class="line">height = <span class="number">1.8</span></span><br></pre></td></tr></table></figure>

<h4 id="1-3-2-变量名的命名规范"><a href="#1-3-2-变量名的命名规范" class="headerlink" title="1.3.2 变量名的命名规范"></a>1.3.2 变量名的命名规范</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 命名规范</span></span><br><span class="line"><span class="number">1.</span> 变量名只能是 字母、数字或下划线的任意组合</span><br><span class="line"><span class="number">2.</span> 变量名的第一个字符不能是数字</span><br><span class="line"><span class="number">3.</span> 关键字不能声明为变量名，常用关键字如下</span><br><span class="line">[<span class="string">&#x27;and&#x27;</span>, <span class="string">&#x27;as&#x27;</span>, <span class="string">&#x27;assert&#x27;</span>, <span class="string">&#x27;break&#x27;</span>, <span class="string">&#x27;class&#x27;</span>, <span class="string">&#x27;continue&#x27;</span>, <span class="string">&#x27;def&#x27;</span>, <span class="string">&#x27;del&#x27;</span>, <span class="string">&#x27;elif&#x27;</span>, <span class="string">&#x27;else&#x27;</span>, <span class="string">&#x27;except&#x27;</span>, <span class="string">&#x27;exec&#x27;</span>, <span class="string">&#x27;finally&#x27;</span>, <span class="string">&#x27;for&#x27;</span>, <span class="string">&#x27;from&#x27;</span>,<span class="string">&#x27;global&#x27;</span>, <span class="string">&#x27;if&#x27;</span>, <span class="string">&#x27;import&#x27;</span>, <span class="string">&#x27;in&#x27;</span>, <span class="string">&#x27;is&#x27;</span>, <span class="string">&#x27;lambda&#x27;</span>, <span class="string">&#x27;not&#x27;</span>, <span class="string">&#x27;or&#x27;</span>, <span class="string">&#x27;pass&#x27;</span>, <span class="string">&#x27;print&#x27;</span>, <span class="string">&#x27;raise&#x27;</span>, <span class="string">&#x27;return&#x27;</span>, <span class="string">&#x27;try&#x27;</span>, <span class="string">&#x27;while&#x27;</span>, <span class="string">&#x27;with&#x27;</span>, <span class="string">&#x27;yield&#x27;</span>]</span><br></pre></td></tr></table></figure>

<h4 id="1-3-3-变量名的命名风格"><a href="#1-3-3-变量名的命名风格" class="headerlink" title="1.3.3 变量名的命名风格"></a>1.3.3 变量名的命名风格</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 风格一：驼峰体</span></span><br><span class="line">AgeOfTony = <span class="number">56</span> </span><br><span class="line">NumberOfStudents = <span class="number">80</span></span><br><span class="line"><span class="comment"># 风格二：纯小写下划线(在python中，变量名的命名推荐使用该风格)</span></span><br><span class="line">age_of_tony = <span class="number">56</span> </span><br><span class="line">number_of_students = <span class="number">80</span></span><br></pre></td></tr></table></figure>

<h4 id="1-3-4-变量值的三大特性"><a href="#1-3-4-变量值的三大特性" class="headerlink" title="1.3.4 变量值的三大特性"></a>1.3.4 变量值的三大特性</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">变量名 <span class="built_in">id</span>   </span><br><span class="line">值的类型 tybe	</span><br><span class="line">变量值   value</span><br></pre></td></tr></table></figure>

<h2 id="二、常量"><a href="#二、常量" class="headerlink" title="二、常量"></a>二、常量</h2><h3 id="2-1-什么是常量"><a href="#2-1-什么是常量" class="headerlink" title="2.1 什么是常量"></a>2.1 什么是常量</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">不会变化的量</span><br></pre></td></tr></table></figure>

<h3 id="2-2-为什么要有常量"><a href="#2-2-为什么要有常量" class="headerlink" title="2.2 为什么要有常量"></a>2.2 为什么要有常量</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">因为有一些不会变化的量存在  比如说是圆周率啊</span><br></pre></td></tr></table></figure>

<h3 id="2-3-怎么使用常量"><a href="#2-3-怎么使用常量" class="headerlink" title="2.3 怎么使用常量"></a>2.3 怎么使用常量</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">没有明确的区分 只有变量名命名为全部大写才会说明这是常量</span><br></pre></td></tr></table></figure>

<h2 id="三、-常见的数据类型"><a href="#三、-常见的数据类型" class="headerlink" title="三、 常见的数据类型"></a>三、 常见的数据类型</h2><h3 id="3-1-数字"><a href="#3-1-数字" class="headerlink" title="3.1 数字"></a>3.1 数字</h3><h4 id="3-1-1-整数int"><a href="#3-1-1-整数int" class="headerlink" title="3.1.1 整数int"></a>3.1.1 整数int</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">整数（<span class="built_in">int</span>） 定义：</span><br><span class="line">	age = <span class="number">18</span></span><br><span class="line">	<span class="built_in">print</span>(<span class="built_in">type</span>(age))</span><br><span class="line">	<span class="built_in">int</span></span><br><span class="line"><span class="comment"># 一般用来 记录 年龄 等级 qq 等等</span></span><br></pre></td></tr></table></figure>

<h4 id="3-1-2-浮点型-float"><a href="#3-1-2-浮点型-float" class="headerlink" title="3.1.2 浮点型 float"></a>3.1.2 浮点型 float</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">浮点型（<span class="built_in">float</span>） 定义：</span><br><span class="line">	height = <span class="number">1.8</span></span><br><span class="line"><span class="comment"># 一般用来 记录 身高 体重  薪资 等等</span></span><br></pre></td></tr></table></figure>

<h3 id="3-2-字符串"><a href="#3-2-字符串" class="headerlink" title="3.2 字符串"></a>3.2 字符串</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">在python中，加了引号的字符就是字符串’</span><br><span class="line">	定义：name = “Ame”</span><br><span class="line"><span class="comment"># 一般用来记录 姓名 性别  种族等等</span></span><br><span class="line">数字可以进行加减乘除等运算，字符串呢？让我大声告诉你，也能</span><br><span class="line">是的，但只能进行<span class="string">&quot;相加&quot;</span>和<span class="string">&quot;相乘&quot;</span>运算</span><br><span class="line">注意<span class="number">1</span>：字符串相加的效率不高</span><br><span class="line">字符串<span class="number">1</span> + 字符串<span class="number">3</span>，并不会在字符串<span class="number">1</span>的基础上加字符串<span class="number">2</span>，而是申请一个全新的内存空间存入字符串<span class="number">1</span>和字符串<span class="number">3</span>，相当字符串<span class="number">1</span>与字符串<span class="number">3</span>的空间被复制了一次，</span><br><span class="line"></span><br><span class="line">注意<span class="number">2</span>：只能字符串加字符串，不能字符串加其他类型</span><br><span class="line"></span><br><span class="line">字符串拼接（只能在字符串之间进行，且只能相加或相乘）	</span><br></pre></td></tr></table></figure>

<h3 id="3-3-列表"><a href="#3-3-列表" class="headerlink" title="3.3 列表"></a>3.3 列表</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">列表则是中括号[]内，其中以逗号分隔，里面有n个数据。</span><br><span class="line"></span><br><span class="line">	<span class="built_in">list</span> = [<span class="number">12</span>, <span class="number">15</span>, <span class="number">56</span>]</span><br><span class="line"></span><br><span class="line">列表嵌套:</span><br><span class="line"></span><br><span class="line">	<span class="built_in">list</span> = [<span class="number">12</span>, <span class="number">15</span>, <span class="number">56</span>,[<span class="number">58</span>, <span class="number">46</span>]]</span><br></pre></td></tr></table></figure>

<h3 id="3-4-字典"><a href="#3-4-字典" class="headerlink" title="3.4 字典"></a>3.4 字典</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">	在&#123;&#125;内用逗号分隔，可以存放多个key:value的值，value可以是任意类型</span><br><span class="line">定义:</span><br><span class="line">	info=&#123;<span class="string">&#x27;name&#x27;</span>:<span class="string">&#x27;egon &#x27;</span>,<span class="string">&#x27;age&#x27;</span>:<span class="number">18</span>,<span class="string">&#x27;sex&#x27;</span>:<span class="number">18</span>&#125;</span><br><span class="line"></span><br><span class="line">	用于标识：存储多个值的情况，每个值都有唯一一个对应的key，可以更为方便高效地取</span><br><span class="line"></span><br><span class="line">字典嵌套：info=&#123;</span><br><span class="line">    <span class="string">&#x27;name&#x27;</span>:<span class="string">&#x27;egon&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;hobbies&#x27;</span>:[<span class="string">&#x27;play&#x27;</span>,<span class="string">&#x27;sleep&#x27;</span>],</span><br><span class="line">    <span class="string">&#x27;company_info&#x27;</span>:&#123;</span><br><span class="line">        <span class="string">&#x27;name&#x27;</span>:<span class="string">&#x27;Oldboy&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;type&#x27;</span>:<span class="string">&#x27;education&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;emp_num&#x27;</span>:<span class="number">40</span>,</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">print</span>(info[<span class="string">&#x27;company_info&#x27;</span>][<span class="string">&#x27;name&#x27;</span>])</span><br></pre></td></tr></table></figure>

<h3 id="3-5-布尔"><a href="#3-5-布尔" class="headerlink" title="3.5 布尔"></a>3.5 布尔</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">bool</span>值只有 <span class="literal">True</span> 和 <span class="literal">False</span></span><br><span class="line"></span><br><span class="line">	a = <span class="number">3</span></span><br><span class="line"></span><br><span class="line">	b = <span class="number">5</span></span><br><span class="line"></span><br><span class="line">如果a &gt; b 则<span class="literal">False</span>    如果a &lt; b <span class="literal">True</span> </span><br></pre></td></tr></table></figure>

<p> <strong>布尔类型的重点知识！！！：</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#所有数据类型都自带布尔值</span></span><br><span class="line"><span class="number">1</span>、<span class="literal">None</span>，<span class="number">0</span>，空（空字符串，空列表，空字典等）三种情况下布尔值为<span class="literal">False</span></span><br><span class="line"><span class="number">2</span>、其余均为真 </span><br></pre></td></tr></table></figure>

<h3 id="3-6-重点："><a href="#3-6-重点：" class="headerlink" title="3.6 重点："></a>3.6 <strong>重点</strong>：</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1.可变类型：在id不变的情况下，value可以变，则称为可变类型，如列表，字典</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2. 不可变类型：value一旦改变，id也改变，则称为不可变类型（id变，意味着创建了新的内存空间）</span></span><br></pre></td></tr></table></figure>

<h2 id="四、与用户交互"><a href="#四、与用户交互" class="headerlink" title="四、与用户交互"></a>四、与用户交互</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># input是输入，外界输入进计算机</span></span><br><span class="line"><span class="comment"># python2 与 python3 的区别</span></span><br><span class="line">  python3</span><br><span class="line">    <span class="built_in">input</span> = (<span class="string">&quot;请您输入: &quot;</span>)</span><br><span class="line">	<span class="built_in">input</span>里所有的都是<span class="string">&quot;str&quot;</span>类型</span><br><span class="line">  python2</span><br><span class="line">	raw_input 实际上就等于python3的 <span class="built_in">input</span></span><br><span class="line">    <span class="built_in">input</span> 则需要输入的时候表明数据类型，例如:</span><br><span class="line">       <span class="built_in">input</span> = (<span class="string">&quot;请您输入: &quot;</span>)</span><br><span class="line">    	在输入的时候字符串就得<span class="string">&quot;Ame&quot;</span>或者列表[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]</span><br><span class="line"><span class="comment"># print则就是计算机输出到外界的</span></span><br><span class="line"><span class="comment"># print输入格式则为</span></span><br><span class="line">	<span class="built_in">print</span> = (<span class="string">&quot;ok，ok&quot;</span>)</span><br></pre></td></tr></table></figure>



<h2 id="五、格式化输入"><a href="#五、格式化输入" class="headerlink" title="五、格式化输入"></a>五、格式化输入</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># python2 与 python3 的不同输入</span></span><br><span class="line"><span class="comment"># python2</span></span><br><span class="line"><span class="number">1</span>、 %s是代表字符串 %d是代表整数 %f是代表浮点型(小数)</span><br><span class="line">    name = <span class="string">&quot;小明&quot;</span></span><br><span class="line">    hobby = <span class="string">&quot;唱 跳 rap 篮球&quot;</span></span><br><span class="line">    age = <span class="number">60</span></span><br><span class="line">    time_years = <span class="number">2.5</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;班上的时常达%0.1f年的练习生%s, 他的爱好就是%s,&quot;</span></span><br><span class="line">          <span class="string">&quot;并且在他%d岁的时候， 编出了鸡你太美舞蹈&quot;</span> % (time_years, name, hobby, age))</span><br><span class="line"><span class="comment"># %f在小数上问题，如需要保留2位小数，则只需要%0.2f即可</span></span><br><span class="line"><span class="comment"># %d在数字保留上面，如 %02d  age = &quot;2&quot;  则会输出成02</span></span><br><span class="line"></span><br><span class="line"><span class="number">2</span>、 <span class="built_in">format</span></span><br><span class="line"><span class="number">2.1</span></span><br><span class="line">    res = <span class="string">&quot;班上的时常达&#123;&#125;年的练习生&#123;&#125;, 他的爱好就是&#123;&#125;,&quot;</span> \</span><br><span class="line">          <span class="string">&quot;并且在他&#123;&#125;岁的时候， 编出了鸡你太美舞蹈&quot;</span>.<span class="built_in">format</span>(<span class="number">2.5</span>, <span class="string">&quot;小明&quot;</span>, <span class="string">&quot;唱 跳 rap 篮球&quot;</span>, <span class="number">60</span>)</span><br><span class="line">    <span class="built_in">print</span>(res)</span><br><span class="line">    班上的时常达<span class="number">2.5</span>年的练习生小明, 他的爱好就是唱 跳 rap 篮球,并且在他<span class="number">60</span>岁的时候， 编出了鸡你太美舞蹈</span><br><span class="line">    </span><br><span class="line"></span><br><span class="line">    res = <span class="string">&quot;班上的时常达&#123;0&#125;&#123;0&#125;年的练习生&#123;1&#125;&#123;1&#125;, 他的爱好就是&#123;2&#125;&#123;2&#125;,&quot;</span> \</span><br><span class="line">    	  <span class="string">&quot;并且在他&#123;3&#125;&#123;3&#125;岁的时候， 编出了鸡你太美舞蹈&quot;</span>.<span class="built_in">format</span>(<span class="number">2.5</span>, <span class="string">&quot;小明&quot;</span>, <span class="string">&quot;唱 跳 rap 篮球&quot;</span>, <span class="number">60</span>)</span><br><span class="line">    <span class="built_in">print</span>(res)</span><br><span class="line">    班上的时常达<span class="number">2.52</span><span class="number">.5</span>年的练习生小明小明, 他的爱好就是唱 跳 rap 篮球唱 跳 rap 篮球,并且在他<span class="number">6060</span>岁的时候， 编出了鸡你太美舞蹈</span><br><span class="line"></span><br><span class="line"><span class="number">2.2</span> </span><br><span class="line">	res = <span class="string">&quot;班上的时常达&#123;year&#125;年的练习生&#123;name&#125;, 他的爱好就是&#123;hobby&#125;,&quot;</span>.<span class="built_in">format</span>(name=<span class="string">&quot;小明&quot;</span>, year=<span class="number">2.5</span>, hobby=<span class="string">&quot;篮球&quot;</span>)</span><br><span class="line">	<span class="built_in">print</span>(res)</span><br><span class="line">    班上的时常达<span class="number">2.5</span>年的练习生小明, 他的爱好就是篮球,</span><br><span class="line">    </span><br><span class="line"><span class="comment"># python3    </span></span><br><span class="line"><span class="number">1</span>、f.string</span><br><span class="line">	name = <span class="string">&quot;Ame&quot;</span></span><br><span class="line">	age = <span class="number">18</span></span><br><span class="line">	<span class="built_in">print</span>(<span class="string">f&quot;我的名字叫<span class="subst">&#123;name&#125;</span>,年龄是<span class="subst">&#123;age&#125;</span>&quot;</span>)</span><br><span class="line">    我的名字叫Ame,年龄是<span class="number">18</span></span><br><span class="line"><span class="comment"># 只能在python3中使用，虽然很简洁简单</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="六、基本运算符"><a href="#六、基本运算符" class="headerlink" title="六、基本运算符"></a>六、基本运算符</h2><h3 id="6-1-赋值运算符"><a href="#6-1-赋值运算符" class="headerlink" title="6.1 赋值运算符"></a>6.1 赋值运算符</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">变量名 赋值符号 变量值</span><br><span class="line">name = <span class="string">&quot;Ame&quot;</span></span><br></pre></td></tr></table></figure>

<h3 id="6-2-算数运算符"><a href="#6-2-算数运算符" class="headerlink" title="6.2 算数运算符"></a>6.2 算数运算符</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">+  -  *  /    //     %     **</span><br><span class="line">加 减 乘 除 除取整数 除取余  幂</span><br><span class="line"><span class="comment"># 字符串只可以相加和相乘</span></span><br><span class="line"><span class="comment">#相加</span></span><br><span class="line">    name = <span class="string">&quot;Ame&quot;</span></span><br><span class="line">    hobby = <span class="string">&quot;basketball&quot;</span></span><br><span class="line">    name + hobby = <span class="string">&quot;Amebasketball&quot;</span></span><br><span class="line"><span class="comment">#相乘</span></span><br><span class="line">    name = <span class="string">&quot;ame&quot;</span></span><br><span class="line">    name * <span class="number">3</span> = <span class="string">&quot;ameameame&quot;</span></span><br><span class="line"><span class="comment"># 数字型是都可以用算术运算符的，但是python对算数精确度不高，所以需要第三方模块</span></span><br></pre></td></tr></table></figure>

<h3 id="6-3-增量赋值"><a href="#6-3-增量赋值" class="headerlink" title="6.3 增量赋值"></a>6.3 增量赋值</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 没有用增量赋值</span></span><br><span class="line">    i = <span class="number">1</span></span><br><span class="line">    i = i + <span class="number">1</span></span><br><span class="line">    <span class="built_in">print</span>(i)</span><br><span class="line"><span class="comment"># 增量赋值</span></span><br><span class="line">    i = <span class="number">1</span></span><br><span class="line">    i += <span class="number">1</span>	</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">1</span>)</span><br><span class="line"><span class="comment"># 以上效果其实是一样的</span></span><br><span class="line"><span class="comment"># 增量赋值有 += -= *= /=</span></span><br></pre></td></tr></table></figure>

<h3 id="6-4-链式赋值"><a href="#6-4-链式赋值" class="headerlink" title="6.4 链式赋值"></a>6.4 链式赋值</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">    x = <span class="number">10</span></span><br><span class="line">    y = x</span><br><span class="line">    z = x</span><br><span class="line"><span class="comment"># 可以优化</span></span><br><span class="line">    x = y = z = <span class="number">10</span>		</span><br></pre></td></tr></table></figure>



<h3 id="6-5-交叉赋值-面试题"><a href="#6-5-交叉赋值-面试题" class="headerlink" title="6.5 交叉赋值(面试题)"></a>6.5 交叉赋值(面试题)</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 使x y互相交换值</span></span><br><span class="line"><span class="comment"># 造第三个变量当中间量</span></span><br><span class="line">    x = <span class="number">10</span></span><br><span class="line">    y = <span class="number">20</span></span><br><span class="line">    z = x</span><br><span class="line">    x = y</span><br><span class="line">    y = z</span><br><span class="line">    <span class="built_in">print</span>(x, y, z)</span><br><span class="line"><span class="comment"># 交叉赋值</span></span><br><span class="line">	x, y = y, x</span><br><span class="line">    <span class="built_in">print</span> = (x, y)</span><br></pre></td></tr></table></figure>

<h3 id="6-6-解压赋值"><a href="#6-6-解压赋值" class="headerlink" title="6.6 解压赋值"></a>6.6 解压赋值</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">name_list = [<span class="string">&#x27;jason&#x27;</span>,<span class="string">&#x27;egon&#x27;</span>,<span class="string">&#x27;tony&#x27;</span>,<span class="string">&#x27;kevin&#x27;</span>]</span><br><span class="line">   name1 = name_list[<span class="number">0</span>]</span><br><span class="line">   name2 = name_list[<span class="number">1</span>]</span><br><span class="line">   name3 = name_list[<span class="number">2</span>]</span><br><span class="line">   name4 = name_list[<span class="number">3</span>]</span><br><span class="line">   <span class="built_in">print</span>(name1,name2,name3,name4)</span><br><span class="line">   <span class="comment"># 解压赋值</span></span><br><span class="line">   name1, name2, name3, name4 = name_list  <span class="comment"># 按照位置一一对应赋值</span></span><br><span class="line">   <span class="built_in">print</span>(name1, name2, name3, name4)</span><br><span class="line"></span><br><span class="line">  <span class="comment"># name1, name2, name3 = name_list  # 少了不行</span></span><br><span class="line">  <span class="comment"># name1, name2, name3, name4, name5 = name_list  										# 多了不行</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># 可以打破个数必须相等的情况</span></span><br><span class="line">  l = [<span class="number">11</span>, <span class="number">22</span>, <span class="number">33</span>, <span class="number">44</span>, <span class="number">55</span>, <span class="number">66</span>, <span class="number">77</span>, <span class="number">88</span>, <span class="number">99</span>]</span><br><span class="line">  a, b, *_, c = l</span><br><span class="line">  <span class="built_in">print</span>(a, b, _, c)</span><br><span class="line">  a, b, *_ = l</span><br><span class="line">  <span class="built_in">print</span>(a, b, _)</span><br></pre></td></tr></table></figure>



<h3 id="6-7-逻辑运算符"><a href="#6-7-逻辑运算符" class="headerlink" title="6.7 逻辑运算符"></a>6.7 逻辑运算符</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">与 <span class="keyword">and</span>  连接多个条件 条件必须都成立</span><br><span class="line">或 <span class="keyword">or</span>   连接多个条件 成立其一即可</span><br><span class="line">非 <span class="keyword">not</span>  取反</span><br><span class="line"><span class="comment"># 当这些混合着用 实际是有优先级的，但是可以用括号去打破这些优先级</span></span><br></pre></td></tr></table></figure>

<h3 id="6-8-比较运算符"><a href="#6-8-比较运算符" class="headerlink" title="6.8 比较运算符"></a>6.8 比较运算符</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt;     &lt;     &lt;=       &gt;=    ==    !=</span><br><span class="line">大于 小于 小于等于 大于等于 等于 不等于</span><br></pre></td></tr></table></figure>

<h3 id="6-9-身份运算符"><a href="#6-9-身份运算符" class="headerlink" title="6.9 身份运算符"></a>6.9 身份运算符</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">is</span> 比较的则是双方地址</span><br><span class="line">== 比较的则是双方值</span><br></pre></td></tr></table></figure>

<h3 id="6-10-成员运算"><a href="#6-10-成员运算" class="headerlink" title="6.10 成员运算"></a>6.10 成员运算</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">in</span>     </span><br><span class="line"><span class="keyword">not</span> <span class="keyword">in</span></span><br></pre></td></tr></table></figure>


            </div>

            <!-- Post Comments -->
            
    <!-- 使用 DISQUS_CLICK -->
<div id="disqus-comment">
    <div id="disqus_thread"></div>

<!-- add animation -->
<style>
	.disqus_click_btn {
            line-height: 30px;
            margin: 0;
            min-width: 50px;
            padding: 0 14px;
            display: inline-block;
            font-family: "Roboto", "Helvetica", "Arial", sans-serif;
            font-size: 14px;
            font-weight: 400;
            text-transform: uppercase;
            letter-spacing: 0;
            overflow: hidden;
            will-change: box-shadow;
            transition: box-shadow .2s cubic-bezier(.4, 0, 1, 1), background-color .2s cubic-bezier(.4, 0, .2, 1), color .2s cubic-bezier(.4, 0, .2, 1);
            outline: 0;
            cursor: pointer;
            text-decoration: none;
            text-align: center;
            vertical-align: middle;
            border: 0;
            background: rgba(158, 158, 158, .2);
            box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
            color: #fff;
            background-color: #7EC0EE;
            text-shadow: 0
        }
</style>
	
<div class="btn_click_load" id="disqus_bt"> 
    <button class="disqus_click_btn">点击查看评论</button>
</div>

<!--
<script type="text/javascript">
$('.btn_click_load').click(function() {
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'http-miccall-tech'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();

    document.getElementById('disqus_bt').style.display = "none";
});
</script>
-->
<script type="text/javascript">
    var disqus_config = function () {
        this.page.url = 'https://gitee.com/AmeX/amelin-ting.git/2017/03/27/Python------%E5%85%A5%E9%97%A8%E7%9F%A5%E8%AF%86%E7%82%B9/';  // Replace PAGE_URL with your page's canonical URL variable
        this.page.identifier = 'https://gitee.com/AmeX/amelin-ting.git/2017/03/27/Python------%E5%85%A5%E9%97%A8%E7%9F%A5%E8%AF%86%E7%82%B9/'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };
</script>

<script type="text/javascript">
    $('.btn_click_load').click(function() {  //click to load comments
        (function() { // DON'T EDIT BELOW THIS LINE
            var d = document;
            var s = d.createElement('script');
            s.src = '//http-miccall-tech.disqus.com/embed.js';
            s.setAttribute('data-timestamp', + new Date());
            (d.head || d.body).appendChild(s);
        })();
        $('.btn_click_load').css('display','none');
    });
</script>
</div>
<style>
    #disqus-comment{
        background-color: #eee;
        padding: 2pc;
    }
</style>


        </div>
        <!-- Copyright 版权 start -->
                <div id="copyright">
            <ul>
                <li>&copy;Powered By <a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/" style="border-bottom: none;">hexo</a></li>
                <li>Design: <a target="_blank" rel="noopener" href="http://miccall.tech " style="border-bottom: none;">miccall</a></li>
            </ul>
            
                <span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
			
        </div>
    </div>
</body>



 	
</html>
